#include "kernel.h"

char string_0[] PROGMEM = "Ready\n";
char string_1[] PROGMEM = "Which prog?\n";
char string_2[] PROGMEM = "Exec prog: ";
char string_3[] PROGMEM = "PID\t RAM\t";
char string_4[] PROGMEM = "\tFlash\t\tState\n";
char string_5[] PROGMEM = "Install\n";
char string_6[] PROGMEM = "Done\n";
char string_7[] PROGMEM = "FREE";
char string_8[] PROGMEM = "RUN";
char string_9[] PROGMEM = "READY";
char string_10[] PROGMEM = "DONE";
char string_11[] PROGMEM = "prog: ";
char string_12[] PROGMEM = " in Proc: ";
char string_13[] PROGMEM = "ram fail\n";
char string_14[] PROGMEM = "flash fail\n";
char string_15[] PROGMEM = " not installed";

PGM_P string_table[] PROGMEM = 
{
    string_0,
    string_1,
    string_2,
    string_3,
    string_4,
	string_5,
	string_6,
	string_7,
	string_8,
	string_9,
	string_10,
	string_11,
	string_12,
	string_13,
	string_14,
	string_15
};

void putchar(char c)
{
	while (!(UCSR0A & 0x20)); 
	UDR0=c;
}

char getchar()
{
	while (!(UCSR0A & 0x80)); 
	return UDR0;
}

void puts(const char *str)
{
	char i = 0;

	while(str[i] != 0)
	{
		putchar(str[i]);
		i++;
	}
}

void puts_f(char i)
{
	char c[15];
	strcpy_P(c, (PGM_P)pgm_read_word(&(string_table[i])));
	c[14] = 0;
	puts(c);
	
}

void itoa(int val, char* buf){
	
	//char buf[6];

	buf[5] = 0;	
	buf[4] = (val % 10) + 48;
	val = val / 10;
	buf[3] = (val % 10) + 48;
	val = val / 10;
	buf[2] = (val % 10) + 48;
	val = val / 10;
	buf[1] = (val % 10) + 48;
	val = val / 10;
	buf[0] = (val % 10) + 48;
	val = val / 10;
	
	//return &buf;
	
}
